home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 2.9 KB | 122 lines | [TEXT/CWIE] |
- //
- // This sample demonstrates how to let the user choose an alias file
- // from an "open" dialog. The basic idea is to intercept the pseudo-
- // item 'sfHookOpenAlias' in a CustomGetFile hook function and transform
- // it into 'getOpen'. This causes the dialog to behave as if the user
- // had clicked the open button. Also, we intercept the item number of
- // a check box we have added to the dialog item template in order to
- // allow the user to choose whether to resolve aliases. Finally,
- // when CustomGetFile returns, we call Alert to let the user know
- // what happened.
- //
- // Complaints and kudos to:
- //
- // Pete Gontier
- // Apple Macintosh Developer Technical Support
- // <gurgle@apple.com>
- //
- // Change history
- //
- // 01/25/95 initial version
- //
- // 01/30/95 use AppendDITL instead of copy of System resources
- //
- // 03/22/96 in DlgHookYDProc, make sure we're dealing with
- // main dialog before doing anything interesting
- //
- // 03/22/96 Use an alert, not DebugStr
- //
-
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #ifndef __FONTS__
- # include <Fonts.h>
- #endif
-
- #ifndef __DIALOGS__
- # include <Dialogs.h>
- #endif
-
- #ifndef __STANDARDFILE__
- # include <StandardFile.h>
- #endif
-
- #ifndef __RESOURCES__
- # include <Resources.h>
- #endif
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static short gItemIndex_CustomGetCheckBox;
-
- enum
- {
- kResID_CustomGetCheckBox = 128,
- kResID_ReportResultsAlert
- };
-
- static pascal short DlgHookYDProc (short item, DialogRef dRef, void *)
- {
- if (GetWRefCon (dRef) == sfMainDialogRefCon)
- {
- if (item == sfHookFirstCall)
- {
- Handle checkBoxDitlH = GetResource ('DITL',kResID_CustomGetCheckBox);
- if (!ResError ( ) && checkBoxDitlH)
- {
- DetachResource (checkBoxDitlH);
- if (ResError ( ))
- ReleaseResource (checkBoxDitlH);
- else
- {
- gItemIndex_CustomGetCheckBox = 1 + CountDITL (dRef);
- AppendDITL (dRef,checkBoxDitlH,appendDITLBottom);
- DisposeHandle (checkBoxDitlH);
- }
- }
- }
- else if (item == gItemIndex_CustomGetCheckBox || item == sfHookOpenAlias)
- {
- short iType; Rect iRect; Handle iHandle; Boolean iValue;
- GetDialogItem (dRef,gItemIndex_CustomGetCheckBox,&iType,&iHandle,&iRect);
- iValue = GetControlValue ((ControlRef) iHandle);
- if (item != sfHookOpenAlias)
- SetControlValue ((ControlRef) iHandle, !iValue);
- else if (!iValue)
- item = getOpen;
- }
- }
-
- return item;
- }
-
- void main (void)
- {
- if (!InitMac ( ))
- {
- StandardFileReply sfr;
- Point sfWhere = {-1,-1};
- CustomGetFile (nil,-1,nil,&sfr,sfGetDialogID,sfWhere,NewDlgHookYDProc(DlgHookYDProc),nil,nil,nil,nil);
-
- if (sfr.sfGood)
- ParamText (sfr.sfFile.name,nil,nil,nil);
- else
- ParamText ("\pAs the world's worst singer would say: 'No reply at all.'",nil,nil,nil);
-
- Alert (kResID_ReportResultsAlert,nil);
- }
- }
-